package com.me.experiment;


import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;


//import com.badlogic.gdx.backends.jogl.JoglApplication;



import android.app.Activity;
import android.content.Intent;

public class MainActivity extends Activity {
	
    String username;  
    int number;
    
	@Override 
	public void onCreate (Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
				
		//getSubject();
		try {
			startInstructions(null);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public void getSubject() {
	      setContentView(R.layout.select_i_subject);		

	   }
	
	public void getName(View view) throws ClassNotFoundException {
	      EditText num = (EditText)findViewById(R.id.isujet);
	      String snum = new String(num.toString());
	      number = 1;
	      
	      setContentView(R.layout.select_name);
	      EditText name = (EditText)findViewById(R.id.name);
	      username = name.getText().toString();   

	   }

	public void startInstructions(View view) throws ClassNotFoundException {
		 //Intent myIntent = new Intent(Experiment1Instructions.this, Scene.class);
	      setContentView(R.layout.instructions);
	      TextView Instructions = (TextView)findViewById(R.id.instructions);
	      Instructions.setText(readTxt());	      
	 }
	
	

	 public void startExperiment(View view) throws ClassNotFoundException {
		 
		 
		 Intent intent = new Intent(this, launch_experiment.class);
			intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			intent.putExtra("s_number", number);
	        startActivity(intent);
	    	finish();

		 	 
	 }

	
public void end_exp(View view) throws ClassNotFoundException {

	
		 //Intent myIntent = new Intent(Experiment1Instructions.this, Scene.class);
		 	 
	 }
	 @Override
	    protected void onResume() {
	        super.onResume();
	    }

	    @Override
	    protected void onPause() {
	        super.onPause();

	    }
	
	    private String readTxt(){

	        InputStream inputStream = getResources().openRawResource(R.raw.instructions);
	        
	        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
	        
	        int i;
	     try {
	      i = inputStream.read();
	      while (i != -1)
	         {
	          byteArrayOutputStream.write(i);
	          i = inputStream.read();
	         }
	         inputStream.close();
	     } catch (IOException e) {
	      // TODO Auto-generated catch block
	      e.printStackTrace();
	     }
	     
	        return byteArrayOutputStream.toString();
	       }
	
}

